﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using SDM.ExamPlanner.BLL;
using SDM.ExamPlanner.DTO;

namespace sdm.exam.ui.ClassAdministration.TeamRegistraion
{
    /// <summary>
    /// Interaction logic for DeleteTeamRegistration.xaml
    /// </summary>
    public partial class DeleteTeamRegistration : UserControl
    {
        private Dictionary<int, string> _schoolClassDictionary;
        readonly Manager<SchoolClass> _schoolClassManager = new Manager<SchoolClass>();
        public DeleteTeamRegistration()
        {
            InitializeComponent();
            PopulateCheckbox();
        }

        private void PopulateCheckbox()
        {
            _schoolClassDictionary = _schoolClassManager.Find().Where(item=>item.IsDeleted==false).ToDictionary(item => item.Id, item => item.Name);
            cbbClass.DataContext = _schoolClassDictionary.Values;
        }

        private void btnSubmit_Click(object sender, RoutedEventArgs e)
        {
            var selectedValue = cbbClass.SelectedValue.ToString();
            var singleOrDefault = _schoolClassManager.Find().SingleOrDefault(item=>item.Name==selectedValue);
            if (singleOrDefault != null)
            {
                singleOrDefault.IsDeleted = true;
                _schoolClassManager.Save(singleOrDefault);
            }
            MessageBox.Show("Class has been deleted.");
        }
    }
}
